layui.config({}).use(['element', 'zlConfig', 'zlContext', 'layer', 'table'], function (exports) {
    var $ = layui.$,
        table = layui.table,
        zlConfig = layui.zlConfig,
        layer = layui.layer,
        zlContext = layui.zlContext,
        form = layui.form,
        infotype = {
            '4B8420226CD54C3EB298A7D328A837AD': '业务信息预警',
            'AB1C83A324414220810CF9E8DBE49493': '系统信息预警',
            'C24EAD1529FD497FB70529FBD6B693F4': '其他信息预警'
        };

    table.render({
        elem: '#warn',
        url: layui.cache['contentPath'] + '/manager/corewarn/query',
        method: 'post',
        response: zlConfig.global.gridResponse,
        page: false,
        sortload: false,
        height: 'full-5',
        cols: [
            [ //表头
                {
                    type: 'numbers',
                    fixed: 'left',
                    title: '#'
                }, {
                    field: 'WARN_TYPE',
                    title: '预警信息类型',
                    width: '15%',
                    sort: true,
                    templet: function (d) {
                        return '<span>' + infotype[d.WARN_TYPE] + '</span>'
                    }
                }, {
                    field: 'WARN_TITLE',
                    title: '预警标题',
                    width: '15%',
                    sort: false
                }, {
                    field: 'WARN_STARTTIME',
                    title: '预警开始时间',
                    sort: true,
                    width: '15%',
                    templet: function (data) {
                        if (data.WARN_STARTTIME) {
                            data.WARN_STARTTIME = data.WARN_STARTTIME.split(" ")[0];
                            return data.WARN_STARTTIME;
                        } else {
                            return "";
                        }

                    }
                }, {
                    field: 'WARN_ENDTIME',
                    title: '预警结束时间',
                    sort: true,
                    width: '15%',
                    templet: function (data) {
                        if (data.WARN_ENDTIME) {
                            data.WARN_ENDTIME = data.WARN_ENDTIME.split(" ")[0];
                            return data.WARN_ENDTIME;
                        } else {
                            return "";
                        }

                    }
                }, {
                    field: 'WARN_CONTENT',
                    title: '预警内容',
                    width: '35%',
                }

            ]
        ],
        event: {
            onRowdbClick: function (field, row) {
                showMxView(row);
            }
        },
    });

    function showMxView(data) {
        if (data.WARN_ENDTIME) {
            data.WARN_ENDTIME = data.WARN_ENDTIME.split(" ")[0];
        }
        if (data.WARN_STARTTIME) {
            data.WARN_STARTTIME = data.WARN_STARTTIME.split(" ")[0];
        }
        data.WARN_TYPE = infotype[data.WARN_TYPE];
        var frm = [
            '<div class="site-block"> <form id ="frmGrid" class="layui-form"  action="">'
            , '	<div class="layui-form-item">'
            , '		<label class="layui-form-label">预警信息类型</label>'
            , '		<div class="layui-input-block">'
            , '			<input type="text" name="WARN_TYPE" required disabled class="layui-input" > '
            , '		</div>'
            , '	</div>'
            , '	<div class="layui-form-item">'
            , '		<label class="layui-form-label">预警标题</label>'
            , '		<div class="layui-input-block">'
            , '			<input type="text" name="WARN_TITLE" required disabled lay-verify="required"  class="layui-input" >'
            , '		</div>'
            , '	</div>'
            , '	<div class="layui-form-item">'
            , '		<label class="layui-form-label">预警开始时间</label>'
            , '		<div class="layui-input-block">'
            , '			<input type="text" name="WARN_STARTTIME" required disabled lay-verify="required"  class="layui-input" >'
            , '		</div>'
            , '	</div>'
            , '	<div class="layui-form-item">'
            , '		<label class="layui-form-label">预警结束时间</label>'
            , '		<div class="layui-input-block">'
            , '	  		<input type="text" name="WARN_ENDTIME" lay-verify="required" disabled class="layui-input">'
            , '		</div>'
            , '	</div>'
            , '	<div class="layui-form-item">'
            , '		<label class="layui-form-label">预警内容</label>'
            , '		<div class="layui-input-block">'
            , '			<textarea class="layui-textarea" type="text" name="WARN_CONTENT" disabled class="layui-input"> </textarea>'
            , '		</div>'
            , '	</div>'
            , '</form></div>'
        ];
        //如果是首页
        var dom;
        if ($(window.parent.document).find('#warn').length > 0) {
            dom = window.parent;
        } else {
            dom = window;
        }
        dom.layer.open({
            type: 1,
            title: '查看',
            id: 'frmGridlayer',
            area: ['100%', '100%'],
            content: frm.join(''),
            success: function (layero, index) {
                zlContext.autoFill($(dom.document).find('#frmGrid'), data);
                form.render();
            },
        });
    }
});